package com.campus.activity.controller;

import com.campus.activity.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 通知管理控制器
 * 
 * @author System
 * @since 2024
 */
@RestController
@RequestMapping("/notifications")
@Tag(name = "通知管理", description = "系统通知相关接口")
@CrossOrigin(origins = "*")
public class NotificationController {

    @GetMapping
    @Operation(summary = "获取用户通知", description = "获取指定用户的所有通知")
    public Result<List<Map<String, Object>>> getUserNotifications(
            @Parameter(description = "用户ID") @RequestParam Integer userId) {
        // 模拟通知数据，实际应该从数据库获取
        List<Map<String, Object>> notifications = new ArrayList<>();
        
        Map<String, Object> notification1 = new HashMap<>();
        notification1.put("id", 1);
        notification1.put("title", "活动报名成功");
        notification1.put("content", "您已成功报名参加校园文化节活动");
        notification1.put("type", "REGISTRATION");
        notification1.put("isRead", false);
        notification1.put("createTime", LocalDateTime.now().minusHours(2));
        notifications.add(notification1);
        
        Map<String, Object> notification2 = new HashMap<>();
        notification2.put("id", 2);
        notification2.put("title", "活动即将开始");
        notification2.put("content", "您报名的学术讲座活动将在明天下午2点开始");
        notification2.put("type", "REMINDER");
        notification2.put("isRead", true);
        notification2.put("createTime", LocalDateTime.now().minusDays(1));
        notifications.add(notification2);
        
        return Result.success(notifications);
    }

    @GetMapping("/unread")
    @Operation(summary = "获取未读通知", description = "获取指定用户的未读通知")
    public Result<List<Map<String, Object>>> getUnreadNotifications(
            @Parameter(description = "用户ID") @RequestParam Integer userId) {
        // 模拟未读通知数据
        List<Map<String, Object>> notifications = new ArrayList<>();
        
        Map<String, Object> notification = new HashMap<>();
        notification.put("id", 1);
        notification.put("title", "活动报名成功");
        notification.put("content", "您已成功报名参加校园文化节活动");
        notification.put("type", "REGISTRATION");
        notification.put("isRead", false);
        notification.put("createTime", LocalDateTime.now().minusHours(2));
        notifications.add(notification);
        
        return Result.success(notifications);
    }

    @PutMapping("/{notificationId}/read")
    @Operation(summary = "标记通知为已读", description = "将指定通知标记为已读")
    public Result<Boolean> markAsRead(
            @Parameter(description = "通知ID") @PathVariable Integer notificationId) {
        // 模拟标记为已读的操作
        return Result.success("通知已标记为已读", true);
    }

    @PutMapping("/read-all")
    @Operation(summary = "标记所有通知为已读", description = "将用户的所有通知标记为已读")
    public Result<Boolean> markAllAsRead(
            @Parameter(description = "用户ID") @RequestParam Integer userId) {
        // 模拟标记所有通知为已读的操作
        return Result.success("所有通知已标记为已读", true);
    }

    @DeleteMapping("/{notificationId}")
    @Operation(summary = "删除通知", description = "删除指定的通知")
    public Result<Boolean> deleteNotification(
            @Parameter(description = "通知ID") @PathVariable Integer notificationId) {
        // 模拟删除通知的操作
        return Result.success("通知删除成功", true);
    }

    @GetMapping("/count/unread")
    @Operation(summary = "获取未读通知数量", description = "获取指定用户的未读通知数量")
    public Result<Integer> getUnreadCount(
            @Parameter(description = "用户ID") @RequestParam Integer userId) {
        // 模拟未读通知数量
        return Result.success(3);
    }
}